/* jslint sloppy: true */
/* global */
var LM = require('../../global');

LM.directive('dropdownMenu', function ($document, $rootScope) {
	angular.element($document).on('click', function () {
		$rootScope.$broadcast('blur');
	});
	return {
		restrict: 'A',
		link: function (scope, e) {
			var c = 'open';
			e.on('click', function (event) {
				event.stopPropagation();
				e[e.hasClass(c) ? 'removeClass' : 'addClass'](c);
			});

			scope.$on('blur', function () {
				e.removeClass(c);
			});
		}
	};
});
